#include <stdio.h>
#include <stdlib.h>
#define P(A,q) while(q>=0) fprintf(stderr,"%d", abs((A>>q--)%2));fprintf(stderr,"\n");q=31

int
getbit (int n, int pos)
{
	return (n >> pos) & 1;
}


void
setbit (int* n, int pos, int bit)
{
	if (bit == 1)
		*n |= 1<<pos;
	else
		*n &= ~(1<<pos);
}


int
main(void)
{
	int x = 0;
	int result = 0;
	register short i = 0;
	register short q = 31;

	freopen("rule.in", "r", stdin);
	freopen("rule.out", "w", stdout);

	scanf("%d", &x);
	result = x;
	P(x,q);

	for (i = 31; i >= 0; --i) {
		if (getbit(x, i)) {
			setbit(&result, i, 1);
			break;
		}
	}
	P(result,q);

	--i;
	i = 30;
	while (i > 0) {
		if (getbit(x, i))
			setbit(&result, i, getbit(x, i+1));
		else
			setbit(&result, i, getbit(x, i-1));
		P(result,q);
		--i;
	}
	setbit(&result, 0, getbit(x,0));
	P(result,q);
	printf("%d\n", result);
}
